package com.taxi.driver.module.main.mine.wallet.withdrawalrecord;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.qianxx.adapter.OnClickListener;
import com.qianxx.view.refreshview.ExRefreshView;
import com.qianxx.view.refreshview.RefreshViewListener;
import com.taxi.driver.R;
import com.taxi.driver.common.Application;
import com.taxi.driver.common.BaseActivity;
import com.taxi.driver.module.main.mine.wallet.withdrawalrecord.dagger.DaggerWithdrawaleRecordComponent;
import com.taxi.driver.module.main.mine.wallet.withdrawalrecord.dagger.WithdrawaleRecordModule;
import com.taxi.driver.module.vo.WithdrawaleRecordVO;
import com.taxi.driver.util.Navigate;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 提现记录
 */
public class WithdrawaleRecordActivity extends BaseActivity implements WithdrawaleRecordContract.View,RefreshViewListener{
    @BindView(R.id.ex_refresh_view)
    ExRefreshView ex_refresh_view;

    LinearLayoutManager linearLayoutManager;
    int nowPage = 1;
    final int REFRESH = 0;
    final int LOADMORE = 1;
    int MODE = REFRESH;
    WithdrawalRecordAdapter adapter;

    @Inject
    WithdrawaleRecordPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdrawale_record);
        ButterKnife.bind(this);

        DaggerWithdrawaleRecordComponent.builder()
                .appComponent(Application.getAppComponent())
                .withdrawaleRecordModule(new WithdrawaleRecordModule(this))
                .build().inject(this);

        initView();
        mPresenter.reqWithdrawaleRecord(nowPage);
    }

    private void initView(){
        ex_refresh_view.setRefreshListener(this);
        linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        ex_refresh_view.setLayoutManager(linearLayoutManager);
        adapter = new WithdrawalRecordAdapter(this);
        ex_refresh_view.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnClickListener<WithdrawaleRecordVO>() {
            @Override
            public void onClick(int position, View view, WithdrawaleRecordVO item) {
                Navigate.openWithdrawaleDetail(WithdrawaleRecordActivity.this,item.cashUuid);
            }
        });

    }

    @Override
    public int getBarColor() {
        return R.color.theme_color;
    }

    @Override
    public void showWithdrawaleRecord(List<WithdrawaleRecordVO> vos) {
        ex_refresh_view.setRefreshing(false);
        if(vos != null && vos.size()>0){
            if(MODE == REFRESH)
                adapter.clear();
            adapter.addAll(vos);
        }else{
            ex_refresh_view.hasNoMoreData(true);
        }
    }

    @Override
    public boolean isActive() {
        return false;
    }

    @Override
    public void onRefresh() {
        MODE = REFRESH;
        nowPage = 1;
        mPresenter.reqWithdrawaleRecord(nowPage);
    }

    @Override
    public void onLoadMore() {
        MODE = LOADMORE;
        nowPage++;
        mPresenter.reqWithdrawaleRecord(nowPage);
    }
}
